//
//  ViewController.m
//  2.18
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *infoLable;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - 弹出提示框(UIAlertView)
- (IBAction)btn1Pressed:(UIButton *)sender {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"弹出框标题" message:@"弹出框信息"
        delegate:self
                                             cancelButtonTitle:@"确定"otherButtonTitles:nil];


    [alertView show];

}


- (IBAction)btn2Pressed:(UIButton *)sender {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"弹出窗口" message:@"中午吃饭了没"
                                                      delegate:self
                                             cancelButtonTitle:@"吃了"otherButtonTitles:@"正在吃",@"还没吃",nil];
    
    
    [alertView show];
    
}

- (IBAction)btn3Pressed:(UIButton *)sender {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"登入" message:@"请输入用户名和密码"
                                                      delegate:self
                                             cancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
    
    alertView.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
    
    
    [alertView show];
    
}

#pragma mark - 弹出操作表(UIActionSheet)
- (IBAction)btn4Pressed:(UIButton *)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"小明:一起吃饭吧?"                 // 标题
                                                       delegate:self                              // 代理人
                                              cancelButtonTitle:@"我吃过了,你去吧."                 // cancelButtong标题
                                         destructiveButtonTitle:@"好的,一起去"                     // destructionButton标题
                                              otherButtonTitles:@"一起吃吃KFC",@"一起去吃MC",nil];  // 其他按钮的标题
    [sheet showInView:self.view];
}






#pragma mark UIAlertVIewDelegate Method


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSLog(@"用户点了第几个按钮=%d,按钮的文字信息:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息:%@",alertView.title);
    
    if([alertView.title isEqualToString:@"登入"])
    {
        NSString *info = [NSString stringWithFormat:@"用户名:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.infoLable.text = info;
    }
}

// 取消的时候
- (void)alertViewCancel:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要弹出的时候
- (void)willPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经弹出
- (void)didPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要消失
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经消失
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}


#pragma mark - UIActionSheetDelegate Method 操作表的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题:%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
    
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
    }
}

// 练习:
// 1. 分析整个应用中当前有多少对象?罗列出来
/**
 *  AppDelegate
    ViewController
    UIAlertView(3个)
    
 
 */


// 2. 使用Reveal查看程序结构



// 3. 使用纯代码实现本程序


@end
